<template>
  <router-view />
</template>

<script setup>
import { RouterView, useRouter } from 'vue-router';
import { onMounted, onUnmounted } from 'vue';
import auth from '@/utils/auth';

const router = useRouter();
let timer = null;

onMounted(() => {
  // 延迟启动定时器，避免在登录过程中干扰
  setTimeout(() => {
    timer = setInterval(() => {
      const currentPath = router.currentRoute.value.path;
      const publicPages = ['/login', '/register', '/forgot'];
      
      // 只在非公开页面进行检查
      if (!publicPages.includes(currentPath)) {
        if (auth.checkTokenExpiration()) {
          auth.logout(false); // 不显示提示信息，避免重复提示
        }
      }
    }, 60000); // 改为每60秒检测一次，减少频率
  }, 10000); // 延迟10秒启动，给登录过程更多时间
});

onUnmounted(() => {
  if (timer) clearInterval(timer);
});
</script>

<style>
#app {
  /* padding-top: 64px; */
}
</style>